﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.GERP.GHRMS.IBLL;

namespace KPIS.GERP.GHRMS.BLL
{
    public class RoyalItemRequestBLL : IRoyalItemRequestBLL
    {
        private static readonly IRoyalItemRequestDAL DAL = DataAccess.CreateRoyalItemRequests();

        private RoyalItemRequestInfo reqInfo = new RoyalItemRequestInfo();
        private RoyalItemInfo riInfo = new RoyalItemInfo();
        private RoyalItemInfo criInfo = new RoyalItemInfo();
        private EmployeeInfo empInfo = new EmployeeInfo();
        private PositionInfo posInfo = new PositionInfo();
        private ClassInfo cInfo = new ClassInfo();
        private JobSiteInfo jsInfo = new JobSiteInfo();
        private EmployeeTypeInfo etInfo = new EmployeeTypeInfo();

        public IList<RoyalItemRequestInfo> ListRoyalItemRequest(int Year, string EmployeeType)
        {
            reqInfo.RequestYear = Year;
            if (EmployeeType.Length > 0)
                etInfo.Sequence = Int32.Parse(EmployeeType);

            return DAL.ListRoyalItemRequest(reqInfo);
        }
        public IList<RoyalItemRequestInfo> ListRoyalItemRequestBySequence(int Sequence)
        {
            return DAL.ListRoyalItemRequest(new RoyalItemRequestInfo(Sequence));
        }

        public void Insert(int RequestYear, string Employee, string Position, string Class
                , string JobSite, Nullable<double> Salary
               , string RequestRoyalItem, string CurrentRoyalItem, bool Need, string Remarks, int CreatedBy)
        {
            if (Employee.Length > 0)
                empInfo.Sequence = Int32.Parse(Employee);
            if (Position.Length > 0)
                posInfo.Sequence = Int32.Parse(Position);
            if (Class.Length > 0)
                cInfo.Sequence = Int32.Parse(Class);
            if (JobSite.Length > 0)
                jsInfo.Sequence = Int32.Parse(JobSite);
            if (RequestRoyalItem.Length > 0)
                riInfo.Sequence = Int32.Parse(RequestRoyalItem);
            if (CurrentRoyalItem.Length > 0)
                criInfo.Sequence = Int32.Parse(CurrentRoyalItem);

            try
            {
                DAL.Insert(new RoyalItemRequestInfo(0, empInfo, posInfo, cInfo, jsInfo, riInfo, criInfo
                    , RequestYear, Salary, Need, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, int RequestYear, string Employee, string Position, string Class
               , string JobSite, Nullable<double> Salary
               , string RequestRoyalItem, string CurrentRoyalItem, bool Need, string Remarks, int UpdatedBy)
        {
            if (Employee.Length > 0)
                empInfo.Sequence = Int32.Parse(Employee);
            if (Position.Length > 0)
                posInfo.Sequence = Int32.Parse(Position);
            if (Class.Length > 0)
                cInfo.Sequence = Int32.Parse(Class);
            if (JobSite.Length > 0)
                jsInfo.Sequence = Int32.Parse(JobSite);
            if (RequestRoyalItem.Length > 0)
                riInfo.Sequence = Int32.Parse(RequestRoyalItem);
            if (CurrentRoyalItem.Length > 0)
                criInfo.Sequence = Int32.Parse(CurrentRoyalItem);

            try
            {
                DAL.Update(new RoyalItemRequestInfo(Sequence, empInfo, posInfo, cInfo, jsInfo, riInfo, criInfo
                    , RequestYear, Salary, Need, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
